//Copyright 2008 Kristian Gundry And Rune Juhl-Petersen
//This file is part of Plain.

//Plain is free software: you can redistribute it and/or modify
//it under the terms of the GNU Lesser General Public License as published by
//the Free Software Foundation, either version 3 of the License, or
//any later version.

//Plain is distributed in the hope that it will be useful,
//but WITHOUT ANY WARRANTY; without even the implied warranty of
//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//GNU Lesser General Public License for more details.

//You should have received a copy of the GNU Lesser General Public License
//along with Plain.  If not, see <http://www.gnu.org/licenses/>.
using System;
using System.Collections.Generic;
using System.Text;
using System.ComponentModel;

namespace Plain.Search
{
    [TypeConverter(typeof(PropertyIdentifierConverter))]
	public class PropertyIdentifier{
		public PropertyIdentifier(string name) {
			this.name = name;
		}
		private string name;

		public string Name
		{
			get { return name; }
			set { name = value; }
		}
		public static Criteria operator <=(PropertyIdentifier prop, string crit){
			return new SimpleCriteria(prop, SimpleCriteriaType.LessThanOrEqual, crit);
		}
		public static Criteria operator ==(PropertyIdentifier prop, string crit)
		{
			return new SimpleCriteria(prop,SimpleCriteriaType.Equal,crit);
		}
		//public static Criteria operator ==(PropertyIdentifier prop, Control crit)
		//{
		//   return new SimpleCriteria(prop, SimpleCriteriaType.Equal, crit);
		//}

		public static Criteria operator !=(PropertyIdentifier prop, string crit)
		{
			return new SimpleCriteria(prop, SimpleCriteriaType.NotEqual, crit);
		}
		public static Criteria operator >=(PropertyIdentifier prop, string crit)
		{
			return new SimpleCriteria(prop,SimpleCriteriaType.GreaterThanOrEqual,crit);
		}
		public static Criteria operator <(PropertyIdentifier prop, string crit)
		{
			return new SimpleCriteria(prop, SimpleCriteriaType.LessThan, crit);
		}
		public static Criteria operator >(PropertyIdentifier prop, string crit)
		{
			return new SimpleCriteria(prop, SimpleCriteriaType.GreaterThan, crit);
		}
		//public static Criteria operator *(PropertyIdentifier prop, string crit)
		//{
		//   return null;
		//}

        public class PropertyIdentifierConverter : TypeConverter {
            public override object  ConvertFrom(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value)
            {
                if (value is string) {return new PropertyIdentifier((string)value); }
                else return null;
            }
            public override bool  CanConvertFrom(ITypeDescriptorContext context, Type sourceType)

            {
                if (sourceType == typeof(string)) { return true; }
                else return false;
            }
        }
        public Criteria StartsWith(object o) {
            return new SimpleCriteria(this, SimpleCriteriaType.StartsWith, o.ToString());
        }
        public Criteria EndsWith(object o) {
            return new SimpleCriteria(this, SimpleCriteriaType.EndsWith, o.ToString());
        }
        public Criteria Contains(object o) {
            return new SimpleCriteria(this, SimpleCriteriaType.Contains, o.ToString());
        }
	}
    
}
